package com.pos.clothes.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pos.clothes.mapper.CategoryMapper;
import com.pos.clothes.pojo.Category;
import com.pos.clothes.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper mapper;
    @Override
    public List<Category> getCategory() {
        return mapper.getCategory();
    }

    @Override
    public void insertCategory(Category category) {
        mapper.insertCategory(category);

    }

    @Override
    public List<Category> searchCategory(String category_name) {
        return mapper.searchCategory(category_name.trim());
    }

    @Override
    public int deleteCategory(int id) {
        return mapper.deleteCategory(id);
    }

    @Override
    public void updateCategory(Category category) {
        mapper.updateCategory(category);
    }

    @Override
    @Transactional(rollbackFor = { RuntimeException.class, Exception.class })
    public PageInfo getList(int pageNum, int pageSize) throws Exception {
        //使用分页插件,核心代码就这一行
        PageHelper.startPage(pageNum, pageSize);
        /* 获取 */
        List<Category> typeList = mapper.getCategory();
        PageInfo pageInfo  = new PageInfo(typeList);
        return pageInfo;
    }

    @Override
    @Transactional(rollbackFor = { RuntimeException.class, Exception.class })
    public PageInfo searchCategory1(String category_name,int pageNum, int pageSize) throws Exception {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo pageInfo  = new PageInfo(mapper.searchCategory(category_name.trim()));
        return pageInfo;
    }


}
